home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
atime89.arc
/
a_time89.c
next >
Wrap
C/C++ Source or Header
|
1989-05-25
|
7KB
|
206 lines
/*
AUTO - TIMESET Version 1.0 by Radoslav Bogdanovic / RadoSoft
Compiled with Sozobon C -- 17 may, 1989
For Microdeal Internal Clock Card and other clock cards working
on the keyboard processor for time & date maintaince.
This program also takes over the function of the AUTOTIME.PRG which
is supplied with Microdeal Clock Card.
For more details see the supplied documentation file.
*/
#include <stdio.h>
#include <ctype.h>
#include <osbind.h>
main(argc,argv)
int argc;
char *argv[];
{
register unsigned long IKBDtimedate;
register unsigned int GEMtime, GEMdate;
int seconds, minutes, hours, day, month, year, fyear;
char *ptr, ans;
printf("\n AUTO - TIMESET Version 1.0\n");
printf(" by Radoslav Bogdanovic / RadoSoft\n");
printf("Compiled with Sozobon C -- 12 May, 1989\n");
/* Following works only with Sozobon C, because other C compilers does
NOT inserts program name (command) in ARGV[0] when program started
from GEM-DESKTOP or program autostarted from AUTO-folder. */
ptr = argv[0];
while (*ptr) ++ptr; /* Find the end of the program name */
ptr -= 6; /* Back up to xx.prg */
if ( isdigit(*ptr) )
fyear = atoi(ptr);
else {
printf("\n This is %s ...\n",argv[0]);
printf(" This program should be renamed to\n");
printf(" A_TIMExx.PRG, where xx is 80 to 99,\n");
printf(" two digits indicating which year\n");
printf(" you want to check against. \n");
printf("\n Press any key to exit\n");
Bconin(2);
exit(0);
}
IKBDtimedate = Gettime();
GEMtime = Tgettime();
GEMdate = Tgetdate();
/* Check if year from filename is same as current IKBD year */
/* If year from filename differs from current IKBD year then */
/* it's assumed that the IKBD time is wrong or zeroed. */
if (fyear != (((IKBDtimedate >> 25) & 0x7F) + 80)) {
IKBDtimeprint("\nThe current IKBD time and date is",IKBDtimedate);
timeprintGEM("The current GEM time is",GEMtime);
dateprintGEM("The current GEM date is",GEMdate);
printf("\nDo you want to change time and date (Y/N): ");
ans = Bconin(2);
if ((ans == 'Y')||(ans == 'y'))
{
printf("\nEnter the new date and time (YY/MM/DD HH:MM): ");
scanf("%d/%d/%d %d:%d",&year,&month,&day,&hours,&minutes);
seconds = 0;
if (year < 100) year += 1900;
IKBDtimedate = ((unsigned long)(year-1980)<<25)
|((unsigned long)month<<21)
|((unsigned long)day<<16)
|((unsigned long)hours<<11)
|((unsigned long)minutes<<5)
|((unsigned long)seconds<<1);
GEMdate = ((unsigned)(year - 1980)<<9)
|((unsigned)month<<5)
|(unsigned)day;
GEMtime = ((unsigned)hours<<11)
|((unsigned)minutes<<5)
|((unsigned)seconds>>1);
Settime(IKBDtimedate);
Tsettime(GEMtime);
Tsetdate(GEMdate);
}
else
setsystemtime(Gettime());
putchar('\n');
}
else
setsystemtime(Gettime());
}
/*-----------------------------------------------------*/
/* fixdigit insert a '0' before number if number < 10 */
/*-----------------------------------------------------*/
fixdigit(buf, number)
char *buf; int number;
{
if (number < 10) {
buf[0] = '0';
sprintf(&buf[1],"%d",number);
}
else
sprintf(buf,"%d",number);
}
/*---------------------------------------------------------------*/
/* IKBDtimeprint decodes IKBD time & date and prints a string */
/*---------------------------------------------------------------*/
IKBDtimeprint(string,time)
char *string; register unsigned long time;
{
int seconds, minutes, hours, day, month, year;
char mins[3], secs[3], days[3], monts[3];
seconds = (time & 0x001F) << 1;
minutes = (time >> 5) & 0x3F;
hours = (time >> 11) & 0x1F;
day = (time >> 16) & 0x1F;
month = (time >> 21) & 0x0F;
year = ((time >> 25) & 0x7F) + 1980;
fixdigit(mins, minutes);
fixdigit(secs, seconds);
fixdigit(days, day);
fixdigit(monts, month);
printf("%s %d:%s:%s on %d/%s/%s\n",string,hours,mins,
secs, year,monts,days);
}
/*-----------------------------------------------------*/
/* timeprintGEM decodes GEM time and prints a string */
/*-----------------------------------------------------*/
timeprintGEM(string,time)
char *string; register unsigned int time;
{
int seconds, minutes, hours;
char mins[3], secs[3];
seconds = (time & 0x001F) << 1;
minutes = (time >> 5) & 0x3F;
hours = (time >> 11) & 0x1F;
fixdigit(mins, minutes);
fixdigit(secs, seconds);
printf("%s %d:%s:%s\n",string,hours,mins,secs);
}
/*-----------------------------------------------------*/
/* dateprintGEM decodes GEM date and prints a string */
/*-----------------------------------------------------*/
dateprintGEM(string,date)
char *string; register unsigned int date;
{
int day, month, year;
char days[3], monts[3];
day = date & 0x1F;
month = (date >> 5) & 0x0F;
year = ((date >> 9) & 0x7F) + 1980;
fixdigit(days, day);
fixdigit(monts, month);
printf("%s %d/%s/%s\n",string,year,monts,days);
}
/*---------------------------------------------------------------------*/
/* setsystemtime sets the GEM system time & date from IKBD time & date */
/*---------------------------------------------------------------------*/
setsystemtime(time)
register unsigned long time;
{
int seconds, minutes, hours, day, month, year;
unsigned int GEMtime, GEMdate;
seconds = (time & 0x001F) << 1;
minutes = (time >> 5) & 0x3F;
hours = (time >> 11) & 0x1F;
day = (time >> 16) & 0x1F;
month = (time >> 21) & 0x0F;
year = (time >> 25) & 0x7F;
GEMdate = ((unsigned)year<<9)
|((unsigned)month<<5)
|(unsigned)day;
GEMtime = ((unsigned)hours<<11)
|((unsigned)minutes<<5)
|((unsigned)seconds>>1);
Tsettime(GEMtime);
Tsetdate(GEMdate);
}